package com.pts.dao;



import com.pts.db.DbUtils;
import com.pts.vo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//用户登录
public class UserDao extends GenericDao {
    @Override
    public boolean isExist(Object obj) {
        User user = (User)obj;
        ResultSet resultSet;
        DbUtils du = new DbUtils();
        Connection connection = du.getConn();
        String sql="select id from user where name=?and pwd=?";
        try {
            PreparedStatement preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setString(1,user.getName());
            preparedStatement.setString(2,user.getPwd());
            resultSet = preparedStatement.executeQuery();
            if(resultSet.next()){
                resultSet.close();
                preparedStatement.close();
                return true;
            }
            resultSet.close();
            preparedStatement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
}
